package clothes.tools.dao.impl;

import clothes.tools.dao.PurchaseDao;
import clothes.tools.pojo.Purchase;

import java.util.List;

public class PurchaseDaoImpl extends BaseDao implements PurchaseDao {
    @Override
    public int addPurchase(Purchase purchase) {
        String sql="insert into purchase(pid,prime,enumber) values(?,?,?)";
        return upDate(sql,purchase.getPid(),purchase.getPrime(),purchase.getEnumber());
    }

    @Override
    public int deletePurchaseById(Integer id) {
        String sql="delete from purchase where eid=?";
        return upDate(sql,id);
    }

    @Override
    public int updatePurchase(Purchase purchase) {
        String sql="update purchase set eid=?,pid=?,prime=?,enumber=? where eid=?";
        return upDate(sql,purchase.getEid(),purchase.getPid(),purchase.getPrime(),purchase.getEnumber(),purchase.getEid());
    }

    @Override
    public Purchase queryPurchaseById(Integer id) {
        String sql="select eid,pid,prime,enumber,etime from purchase where eid=?";
        return queryForOne(sql,Purchase.class,id);
    }

    @Override
    public List<Purchase> queryPurchase() {
        String sql="select * from purchase";
        return queryForList(sql,Purchase.class);
    }

    @Override
    public List<Purchase> queryPurchase(String page, String limit) {
        String sql="select * from purchase limit ?,?";
        int page1=Integer.parseInt(page);
        int limit1=Integer.parseInt(limit);
        return queryForList(sql,Purchase.class,(page1-1)*limit1,limit1);
    }
}
